package com.project.server.garden;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.StringUtils;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.garden.TGardenSupervisory;
import com.project.server.service.estates.ITEstatesAssetsService;
import com.project.server.service.garden.ITGardenSupervisoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 园区监控信息Controller
 *
 * @author project
 * @date 2021-07-01
 */
@RestController
@RequestMapping("/server/supervisory")
public class TGardenSupervisoryController extends BaseController {

    @Resource
    private ITGardenSupervisoryService tGardenSupervisoryService;

    @Resource
    private ITEstatesAssetsService tEstatesAssetsService;

    /**
     * 查询园区监控信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:supervisory:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGardenSupervisory tGardenSupervisory) {
        startPage();
        List<TGardenSupervisory> list = tGardenSupervisoryService.selectTGardenSupervisoryList(tGardenSupervisory);
        return getDataTable(list);
    }


    /**
     * 导出园区监控信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:supervisory:export')")
    @Log(title = "园区监控信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TGardenSupervisory tGardenSupervisory) {
        List<TGardenSupervisory> list = tGardenSupervisoryService.selectTGardenSupervisoryList(tGardenSupervisory);
        ExcelUtil<TGardenSupervisory> util = new ExcelUtil<TGardenSupervisory>(TGardenSupervisory.class);
        return util.exportExcel(list, "园区监控信息列表");
    }

    /**
     * 获取园区监控信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:supervisory:query')")
    @GetMapping(value = "/{supervisoryId}")
    public AjaxResult getInfo(@PathVariable("supervisoryId") Long supervisoryId) {
        return AjaxResult.success(tGardenSupervisoryService.selectTGardenSupervisoryById(supervisoryId));
    }

    /**
     * 新增园区监控信息
     */
    @PreAuthorize("@ss.hasPermi('server:supervisory:add')")
    @Log(title = "园区监控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TGardenSupervisory tGardenSupervisory) {
        if (StringUtils.isEmpty(String.valueOf(tGardenSupervisory.getSupervisoryId()))) {
            return AjaxResult.error();
        }
        return toAjax(tGardenSupervisoryService.insertTGardenSupervisory(tGardenSupervisory));
    }

    /**
     * 修改园区监控信息
     */
    @PreAuthorize("@ss.hasPermi('server:supervisory:edit')")
    @Log(title = "园区监控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TGardenSupervisory tGardenSupervisory) {
        return toAjax(tGardenSupervisoryService.updateTGardenSupervisory(tGardenSupervisory));
    }

    /**
     * 删除园区监控信息
     */
    @PreAuthorize("@ss.hasPermi('server:supervisory:remove')")
    @Log(title = "园区监控信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supervisoryIds}")
    public AjaxResult remove(@PathVariable Long[] supervisoryIds) {
        return toAjax(tGardenSupervisoryService.deleteTGardenSupervisoryByIds(supervisoryIds));
    }

    /**
     * 获取所有设备点位信息
     */
//    @PreAuthorize("@ss.hasPermi('server:guard:export')")
    @Log(title = "获取所有设备点位信息", businessType = BusinessType.OTHER)
    @GetMapping("/monitor/queryAll")
    public AjaxResult monitorQuery() {
        return AjaxResult.success(tEstatesAssetsService.selectDeviceList());
    }

    @Log(title = "获取录像回放设备列表", businessType = BusinessType.OTHER)
    @GetMapping("/monitor/queryVideotape")
    public AjaxResult monitorVideotape() {
        return AjaxResult.success(tEstatesAssetsService.selectDeviceList());
    }

}
